//
//  MonthViewEventcell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/8.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

class MonthViewEventcell: UITableViewCell {
    
    let leadingWidth : CGFloat = 5.0
    
    var event: EventInMonthView?{
        didSet{
            setNeedsDisplay()
        }
    }
    
    //    var eventColorType = 4 // 5 & nil
    //    var eventCircleType : CircleIconType // circleType = 0(空心圆) 1(半空心圆) 2(实心圆)
    //    var eventBarType : BarType! //begin end neither
    //
//    var lineType : CellLineType! //first last middle
    //
    //    var eventTitle = ""
    
    @IBOutlet weak var eventTitleLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.selectionStyle = .None
        
    }
    
    override func drawRect(rect: CGRect) {
        
        eventTitleLabel.text = event?.eventTitle
        
        let eventColorType = (event?.eventColorType)!
        let eventCircleType = (event?.eventCircleType)!
        let eventBarType = (event?.eventBarType)!
        let lineType = (event?.eventLineType)!
        //        lineType = CellLineType.LineFirst
        
        //画线
        switch lineType{
        case .LineFirst:
            //first
            DrawUtil.drawLine(CGPointMake( leadingWidth, self.frame.height/2), end: CGPointMake( leadingWidth, self.frame.height), withColor: UIColor.lightGrayColor(), withWidth: 1)
            break
        case .LineMiddle:
            DrawUtil.drawLine(CGPointMake( leadingWidth, 0), end: CGPointMake( leadingWidth, self.frame.height), withColor: UIColor.lightGrayColor(), withWidth: 1)
            break
            
        case .LineLast:
            DrawUtil.drawLine(CGPointMake( leadingWidth, 0), end: CGPointMake( leadingWidth, self.frame.height/2), withColor: UIColor.lightGrayColor(), withWidth: 1)
            break
            
        case .LineNone:
            break
            
        }
        
        //画圈
        DrawUtil.drawCircle(CGPointMake( leadingWidth, self.frame.height/2), radius: self.frame.height/2 - 3, circleType: eventCircleType, circleColor: YOKOColor.TypeColors[eventColorType], linewidth: 2.0)
        
        //画跨天事件的条条
        switch eventBarType {
        case .BarStart:
            DrawUtil.drawLine(CGPointMake( leadingWidth, self.frame.height/2), end: CGPointMake( self.frame.width, self.frame.height/2), withColor: YOKOColor.TypeColors[eventColorType].colorWithAlphaComponent(0.4), withWidth: self.frame.height-6)
            break
            
        case .BarMiddle:
            DrawUtil.drawLine(CGPointMake( 0, self.frame.height/2), end: CGPointMake( self.frame.width, self.frame.height/2), withColor: YOKOColor.TypeColors[eventColorType].colorWithAlphaComponent(0.4), withWidth: self.frame.height-6)
            break
            
        case .BarEnd:
            DrawUtil.drawLine(CGPointMake( 0, self.frame.height/2), end: CGPointMake( leadingWidth, self.frame.height/2), withColor: YOKOColor.TypeColors[eventColorType].colorWithAlphaComponent(0.4), withWidth: self.frame.height-6)
            break
            
        default:
            break
        }
    }
    
}
